{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d4252c29",
   "metadata": {},
   "source": [
    "\n",
    "## 购物车程序\n",
    "* 1.用户输入使用input，input的使用，结果使用是一个字符串\n",
    "* 2.循环遍历商品列表，将商品信息按照一定格式输出\n",
    "* 3.一定格式：商品编号，商品名称，商品价格\n",
    "* 4.range会根据商品列表的长度变化而变化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a70c4e18",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-2-f9b822577910>, line 21)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-2-f9b822577910>\"\u001b[1;36m, line \u001b[1;32m21\u001b[0m\n\u001b[1;33m    elif choice == \"q\"\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "goods_list =[\n",
    "    ['奶茶',8],['珍珠奶茶',10],['果茶',12],['柠檬茶',11]\n",
    "]\n",
    "user_shopping_car = []\n",
    "Alipay = input(\"请输入您的余额\")\n",
    "print(\"------欢迎选购------\")\n",
    "for i in range(len(goods_list)):\n",
    "    print(\"商品编号:%s,商品名称:%s,商品价格:%s\"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "choice = input(\"请输入购买商品的编号:\")\n",
    "if choice.isdigit():\n",
    "    choice = int(choice) \n",
    "    if choice > len(goods_list):\n",
    "        print(\"您选择的商品不存在\")\n",
    "    else:\n",
    "        if Alipay > goods_list[choice][1]: \n",
    "            user_shopping_car.append(goods_list[choice])\n",
    "            Alipay = Alipay - goods_list[choice][1]\n",
    "            print(\"您的账户余额还有: %s 元\"%(goods_list[choice]))\n",
    "else:\n",
    "        print(\"您的余额不足，请更换支付方式\")\n",
    "        elif choice == \"q\"\n",
    "        print(\"用户购物车:\",user_shopping_car)\n",
    "        print(\"您的余额还有:\",Alipay)\n",
    "        break\n",
    "        else:\n",
    "            print(\"请输入商品编号\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a6fdcbf",
   "metadata": {},
   "source": [
    "## 元组\n",
    "* 1.它是和list几乎完全一样的序列数据\n",
    "* 2.它与list不同的地方是，**不可变**（因为不可变，所以几乎没有方法）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4d090776",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = \"lxx\",\"yibo\",\"sean\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "569f9f5b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('lxx', 'yibo', 'sean')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "641523ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bf29c4f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# tuple=元组"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6689f960",
   "metadata": {},
   "source": [
    "# 字典(dict)\n",
    "\n",
    "> 1. 字典的创建方式\n",
    ">> 1. 直接创建字典，按照字典的结构：{key1:value1 , key2:value2 , ......}\n",
    ">> 2. dict()创建字典，dict(key1=value1，key2:value2， ...)\n",
    ">> 3. 新建空字典，然后增加值的方式创建字典\n",
    "> 2. 字典的性质"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56b1d84d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "46ac7aa5",
   "metadata": {},
   "source": [
    "# 课后作业\n",
    "## 字典运用\n",
    "## 字典练习\n",
    "> 1. 请尝试使用和学习字典的方法（必须完成）\n",
    "> 2. 给一组数据，利用字典查询的方式尝试查找指定的数据（尝试完成）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f384b83d",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_info = {\n",
    "    \"stu10001\":\"lxx\",\n",
    "    \"stu10002\":\"yibo\",\n",
    "    \"stu10003\":\"sean\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "38ad06ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu10001': 'lxx', 'stu10002': 'yibo', 'stu10003': 'sean'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5ef1cd21",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu10001 = {\n",
    "    \"name\":\"lxx\",\n",
    "    \"age\":19,\n",
    "    \"Job\":\"student\"\n",
    "}\n",
    "stu10002 = {\n",
    "    \"name\":\"yibo\",\n",
    "    \"age\":24,\n",
    "    \"job\":\"singer,dancer,actor\"    \n",
    "}\n",
    "stu10003 = {\n",
    "    \"name\":\"sean\",\n",
    "    \"age\":30,\n",
    "    \"job\":\"actor,singer\"    \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d7ce3b30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu10001': 'lxx', 'stu10002': 'yibo', 'stu10003': 'sean'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6b91f0d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_info_02 = dict(\n",
    "   stu10001 =  \"lxx\",\n",
    "   stu10002 =  \"yibo\",\n",
    "   stu10003 =  \"sean\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "86f2effd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu10001': 'lxx', 'stu10002': 'yibo', 'stu10003': 'sean'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info_02"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8d8f1a65",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu10001': 'lxx', 'stu10002': 'yibo', 'stu10003': 'sean'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第三中创建字典的方式，新建空字典，然后增加值的方式创建字典\n",
    "\n",
    "stu_info_03 = {}\n",
    "\n",
    "stu_info_03['stu10001'] = \"lxx\" # 字典的增加\n",
    "stu_info_03['stu10002'] = \"yibo\" \n",
    "stu_info_03['stu10003'] = \"sean\" \n",
    "stu_info_03"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f73f4287",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu10001': 'lxx', 'stu10002': 'yibo', 'stu10003': 'sean'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info_03"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "039864d7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
